import { alova } from '@/service/request';

/** get Template page */
export function paginateTemplate(params?: Api.SearchParams) {
  return alova.Get<Api.PageRow>('/cms/template/paginate', {
    params
  });
}

/** get all Template */
export function listTemplate() {
  return alova.Get<Api.Row[]>('/cms/template/list');
}

/** create Template */
export function createTemplate(data?: Api.Model) {
  return alova.Post<boolean>('/cms/template/create', data);
}

/** update Template */
export function updateTemplate(data?: Api.Model) {
  return alova.Post<boolean>('/cms/template/update', data);
}

/** delete Template */
export function deleteTemplate(params: Api.DeleteParams) {
  return alova.Post<boolean>('/cms/template/delete', undefined, { params });
}

/** delete Template */
export function batchDelTemplate(params: Api.BatchDeleteParams) {
  return alova.Post<boolean>('/cms/template/batchDel', undefined, { params });
}

export function treeTemplateFile(data?: { siteId?: number }) {
  return alova.Post<Api.Node[]>('/cms/template/treeFile', data);
}

export function updateTemplateFile(data: { id: string; siteId?: number; content: string }) {
  return alova.Post<boolean>('/cms/template/updateFile', data);
}

export function getTemplateFile(data: { id: string; siteId?: number }) {
  return alova.Post<string>('/cms/template/getFile', data);
}

/** AI generate template */
export function generateTemplateByAI(data: { prompt: string; config: any; businessData: string; templateId?: number }) {
  return alova.Post<boolean>('/cms/template/ai-generate', data);
}
